package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         49,
		Discription: "将同一串字符的不同排列组合归类",
		Level:       2,
		Labels: map[string]int{
			"哈希表": 1,
		},
	})
}

func GroupAnagrams(strs []string) [][]string {
	//维护一个map[[26]int][]string即可，统计每个单词中各个字符的出现次数
	countMap := make(map[[26]int][]string, 0)
	for _, str := range strs {
		var count [26]int
		for i := range str {
			count[int(str[i]-'a')]++
		}
		countMap[count] = append(countMap[count], str)
	}

	res := make([][]string, 0)
	for _, words := range countMap {
		res = append(res, words)
	}

	return res
}
